package config

import (
	"fmt"
	"io/ioutil"
	"log"

	"gopkg.in/yaml.v2"
)

// 配置文件
type Conf struct {
	Database     Database     `yaml:"database"`
	Daxinxinbase Daxinxinbase `yaml:"daxinxinbase"`
	Tenders      Tenders      `yaml:"tenders"`
}
type Database struct {
	Mysql        string `yaml:"mysql"`
	MaxIdleConns int    `yaml:"max_idle_conns"`
	MaxOpenConns int    `yaml:"max_open_conns"`
}
type Daxinxinbase struct {
	Host     string `yaml:"host"`
	Port     string `yaml:"port"`
	Charset  string `yaml:"charset"`
	User     string `yaml:"user"`
	Pwd      string `yaml:"pwd"`
	Database string `yaml:"database"`
}

type Tenders struct {
	Host     string `yaml:"host"`
	Port     string `yaml:"port"`
	Charset  string `yaml:"charset"`
	User     string `yaml:"user"`
	Pwd      string `yaml:"pwd"`
	Database string `yaml:"database"`
}

var Confok Conf

// 获取配置文件方法
func InitConf() {

	//导入配置文件
	yamlFile, err := ioutil.ReadFile("./config/config.yaml")
	if err != nil {
		fmt.Println(err.Error())
	}

	//将配置文件读取到结构体中
	err = yaml.Unmarshal(yamlFile, &Confok)
	if err != nil {
		fmt.Println(err.Error())
	}

	log.Println("配置文件初始化...")
}
